class Gain {
	constructor(THIS) {
		this.THIS = THIS
  }
  get value(){
    return this.THIS.value
  }
  set value(value){
    this.THIS.value = value
  }
}
class GainNode {
	constructor(THIS) {
		this.THIS = THIS
	}
	get gain() {
		return new Gain(this.THIS.gain)
	}
	connect(data) {
		this.THIS.connect(data.THIS)
	}
}
class AudioBuffer {
	constructor(THIS) {
		this.THIS = THIS
	}
	getChannelData(channel) {
		return this.THIS.getChannelData(channel)
	}
}
class AudioBufferSourceNode {
	constructor(THIS) {
		this.THIS = THIS
	}
	get playbackRate() {
		return this.THIS.playbackRate
	}
	set buffer(buffer) {
		this._buffer = buffer
		this.THIS.buffer = buffer.THIS
	}
	get buffer() {
		return this._buffer
	}
	set loop(loop) {
		this.THIS.loop = loop
	}
	get loop() {
		return this.THIS.loop
	}
	set loopStart(loopStart) {
		this.THIS.loopStart = loopStart
	}
	set loopEnd(loopEnd) {
		this.THIS.loopEnd = loopEnd
	}
	set onended(onended) {
		this.THIS.onended = onended
	}
	start(when, offset, duration) {
		this.THIS.start(when, offset, duration)
	}
	stop() {
		this.THIS.stop()
	}
	connect(data) {
		this.THIS.connect(data.THIS)
	}
}
class Panner {
	constructor(THIS) {
		this.THIS = THIS
	}
	set panningModel(panningModel) {
    this._panningModel = panningModel
		this.THIS.panningModel = panningModel
  }
  get panningModel(){
    return this._panningModel
  }
	connect(data) {
		 this.THIS.connect(data.THIS)
	}
}
class AudioListener {
	constructor(THIS) {
    this.THIS = THIS
  }
	get positionX() {
		return 0;
	}
	get positionY() {
		return 0;
	}
	setPosition() {

	}
	setOrientation() {

	}
}
export default class AudioContext {
	constructor() {
		this.THIS = wx.createWebAudioContext()
	}
	get sampleRate() {
		return this.THIS.sampleRate
	}
	createBuffer(numOfChannels, length, sampleRate) {
		return new AudioBuffer(this.THIS.createBuffer(numOfChannels, length, sampleRate))
	}
	createBufferSource() {
		return new AudioBufferSourceNode(this.THIS.createBufferSource())
	}
	createPanner() {
		return new Panner(this.THIS.createPanner())
	}
	get listener() {
		return new AudioListener(this.THIS.listener)
	}
	get currentTime() {
		return this.THIS.currentTime
	}
	get destination() {
		return this.THIS.destination
	}
	createGain() {
		return new GainNode(this.THIS.createGain())
	}
	createMediaElementSource(mediaElement) {

	}
	createMediaStreamSource(mediaStream) {

	}
	decodeAudioData(arrayBuffer, successCallback, errorCallback) {
		return new Promise((resolve, reject) => {
			this.THIS.decodeAudioData(arrayBuffer, buffer => {
				const web_buffer = new AudioBuffer(buffer)
				resolve(web_buffer)
				if (successCallback) {
					successCallback(web_buffer)
				}
			}, err => {
				reject(err)
				if (errorCallback) {
					errorCallback(err)
				}
			})
		})
	}
}
